package com.example.threaddemo;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Date 2021/8/8
 * @Created by Jonathan
 */
@Slf4j
public class ExceptionHandler implements Runnable {
    public static void main(String[] args) throws Exception {
        // 设置捕获器
        Thread.setDefaultUncaughtExceptionHandler(new MyThreadUncaughtExceptionHandler());
        //
        new Thread(new ExceptionHandler(), "t1").start();
        TimeUnit.SECONDS.sleep(1);
        new Thread(new ExceptionHandler(), "t2").start();
        TimeUnit.SECONDS.sleep(1);
        new Thread(new ExceptionHandler(), "t3").start();
        TimeUnit.SECONDS.sleep(1);
        new Thread(new ExceptionHandler(), "t4").start();
        TimeUnit.SECONDS.sleep(1);
    }

    @Override
    public void run() {
        log.info("hello world");
        throw new RuntimeException("hhhh");
    }
}
